/**
 * @author lteng
 * @time 2022-06-18 17:29:20 
 */
 
package liteng.study.cn.stuscore.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import liteng.study.cn.stuscore.dao.ScoreDao;
import liteng.study.cn.stuscore.entity.EType;
import liteng.study.cn.stuscore.entity.Score;

/**
 * 学生成绩数据处理接口实现类
 */
public class ScoreDaoImpl extends BaseDao implements ScoreDao {

	@Override
	public void add(Score score) {
		String sql = "INSERT INTO score(sid,eid,score)" + " VALUES (?,?,?)";
		add(sql, score.getSid(), score.getEid(),score.getScore());

	}

	@Override
	public void update(Score score) {
		// TODO Auto-generated method stub
		String sql = "UPDATE score SET score=? WHERE sid=? AND eid=?";
		update(sql,score.getScore(),score.getSid(), score.getEid());

	}

	@Override
	public void delete(Score score) {
		// TODO Auto-generated method stub
		String sql = "DELETE FROM score WHERE sid=? AND eid=?";
		delete(sql, score.getSid(),score.getEid());
	}

	@Override
	public Score qryOne(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Score qryScore(long sid, int eid) {
		// TODO Auto-generated method stub
		String sql = "SELECT eid,sid, score FROM score WHERE sid=? AND eid=?";
		
		ResultSet rs = getResl(sql, sid,eid);
		if (rs==null) {
			return null;
		}
		Score score = null;
		try {
			while (rs.next()) {
				
				score = new Score();
				score.setEid(rs.getInt("eid"));
				score.setSid(rs.getLong("sid"));
				score.setScore(rs.getFloat("score"));
			}
		} catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return score;
	}

}
